<template>
	<view class="main">
		<u-navbar :is-back="true" title="添加红包" :background="background" back-icon-color="#000000" title-color="#000"
			title-bold="true"></u-navbar>
		<view class="type">
			<view class="tit">
				红包金额
			</view>
			<input type="text" placeholder="请输入金额" v-model="price" />
		</view>

		<view class="confirm" @click="addgift">
			添加红包
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#fff'
				},
				price: '',

			}
		},
		onLoad() {


		},
		mounted() {

		},
		onShow() {},
		methods: {
			addgift() {
				if(this.price==''){
					uni.showToast({
						title: '请输入红包金额',
						icon: 'none',
						duration: 1000
					})
				}else{
					global.$http.request({
						url: '/shopapi/activity/envelopesadd',
						data: {
							token: uni.getStorageSync('token'),
							price: this.price
						}
					}).then(res => {
						if (res.data.code == 200) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 1000
							})
							
							setTimeout( function(){
								 let pages = getCurrentPages(); // 当前页面
								 let beforePage = pages[pages.length - 2]; // 前一个页面
								uni.navigateBack({
									delta:1,
									   success: function() {
									         beforePage.onLoad(); // 执行前一个页面的onLoad方法
									     }
								})
							},1000)
						} 
					})
				}
			}
		}
	}
</script>
<style lang="scss">
	page {
		font-family: PingFang SC;
		width: 750rpx;
		margin: 0 auto;

		background-color: #f7f7f7;

		.main {
			width: 750rpx;
			margin: 0 auto;

			.type {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 41rpx 19rpx;
				margin-top: 10rpx;
				background-color: #fff;

				.tit {
					font-size: 30rpx;
					font-weight: bold;
					color: #060606;
				}

				input {
					width: 60%;
					text-align: right;
				}

			}

			.confirm {
				width: 690rpx;
				background: #FE4E00;
				border-radius: 49px;
				position: absolute;
				bottom: 30rpx;
				left: 30rpx;
				text-align: center;
				padding: 34rpx 0;
				background: #FE4E00;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}
</style>
